package com.star.banner.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.star.banner.dto.BannerPageDTO;
import com.star.banner.dto.BannerSaveDTO;
import com.star.banner.dto.BannerUpdateDTO;
import com.star.banner.entity.Banner;
import com.star.banner.service.BannerService;
import com.star.banner.vo.BannerVO;
import com.star.core.base.BaseController;
import com.star.security.annotations.Authorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 横幅
 *
 * @author lty
 */
@RestController
@RequestMapping("/banner")
public class BannerController extends BaseController {

    @Resource
    private BannerService bannerService;

    /**
     * 新增
     * @param dto
     */
    @Authorize("banner")
    @PostMapping
    public void save(BannerSaveDTO dto){
        bannerService.save(dto);
    }

    /**
     * 删
     * @param ids
     */
    @Authorize("banner")
    @DeleteMapping
    public void deleteByIds(@RequestBody List<Long> ids){
        bannerService.deleteByIds(ids);
    }

    /**
     * 修改
     * @param dto
     */
    @Authorize("banner")
    @PutMapping
    public void update(@Validated @RequestBody BannerUpdateDTO dto){
        bannerService.update(dto);
    }

    /**
     * 分页查询
     * @param dto
     * @return
     */
    @Authorize("banner")
    @GetMapping("/page")
    private IPage<BannerVO> page(BannerPageDTO dto){
        return bannerService.page(dto);
    }

    /**
     * 获取详情
     *
     * @param id id
     * @return <{@link Banner}>
     */
    @Authorize("banner")
    @GetMapping("/{id}")
    public Banner getDetail(@PathVariable Long id) {
        return bannerService.getDetail(id);
    }

}
